<template>
  <div class="app-container">
    <div style="padding-bottom: 10px">
      <el-input
        v-model.trim="listQuery.qudao"
        placeholder="请输入渠道账号进行搜索"
        style="width: 220px;"
        class="filter-item"
        @keyup.enter.native="getList"
      />
      <el-button
       plain
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="getList"
      >搜索</el-button>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="序号" align="center" width="80" type="index" />
      <el-table-column label="今日在线渠道" align="center" min-width="120">
        <template slot-scope="{row}">
          <span>{{ row.qudao }}</span>
        </template>
      </el-table-column>
      <el-table-column label="所归属代理" min-width="120" align="center">
        <template slot-scope="{row}">
          <span>{{ row.parent }}</span>
        </template>
      </el-table-column>
      <el-table-column label="UV" min-width="120" align="center">
        <template slot-scope="{row}">
          <span>{{ row.uv }}</span>
        </template>
      </el-table-column>

       <el-table-column label="PV" min-width="120" align="center">
        <template slot-scope="{row}">
          <span>{{ row.pv }}</span>
        </template>
      </el-table-column>

      <el-table-column label="点击" min-width="120" align="center">
        <template slot-scope="{row}">
          <span>{{ row.ex }}</span>
        </template>
      </el-table-column>

      <el-table-column label="uv点击率" min-width="120" align="center">
        <template slot-scope="{row}">
          <span>{{ (row.ex / row.uv  * 100).toFixed(2) }}%</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total > listQuery.limit" :total="total" class="pageShow" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <pagination v-show="total > listQuery.limit" layout="prev, pager, next" :small="true" class="pageHidden" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import { fetchList } from '@/api/admin/online'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'Online',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        qudao: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.DATA.list
        this.total = response.DATA.total
        this.listLoading = false
      })
    }
  }
}
</script>

<style scoped>
  .pageHidden{
    display: none;
  }
  @media (max-width:550px) {
    .pageShow {
      display: none;
    }
    .pageHidden {
      display: block;
    }
    .pickertime{
      width: 100%;
    }
  }
</style>
